plugin.js 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471
  1. /**
  2. * TinyMCE version 6.8.6 (TBD)
  3. */
  4. /**
  5. * Prism: Lightweight, robust, elegant syntax highlighting
  6. *
  7. * @license MIT <https://opensource.org/licenses/MIT>
  8. * @author Lea Verou <https://lea.verou.me>
  9. * @namespace
  10. * @public
  11. */
  12. (function () {
  13. 'use strict';
  14. var global$2 = tinymce.util.Tools.resolve('tinymce.PluginManager');
  15. const isNullable = a => a === null || a === undefined;
  16. const isNonNullable = a => !isNullable(a);
  17. const noop = () => {
  18. };
  19. const constant = value => {
  20. return () => {
  21. return value;
  22. };
  23. };
  24. class Optional {
  25. constructor(tag, value) {
  26. this.tag = tag;
  27. this.value = value;
  28. }
  29. static some(value) {
  30. return new Optional(true, value);
  31. }
  32. static none() {
  33. return Optional.singletonNone;
  34. }
  35. fold(onNone, onSome) {
  36. if (this.tag) {
  37. return onSome(this.value);
  38. } else {
  39. return onNone();
  40. }
  41. }
  42. isSome() {
  43. return this.tag;
  44. }
  45. isNone() {
  46. return !this.tag;
  47. }
  48. map(mapper) {
  49. if (this.tag) {
  50. return Optional.some(mapper(this.value));
  51. } else {
  52. return Optional.none();
  53. }
  54. }
  55. bind(binder) {
  56. if (this.tag) {
  57. return binder(this.value);
  58. } else {
  59. return Optional.none();
  60. }
  61. }
  62. exists(predicate) {
  63. return this.tag && predicate(this.value);
  64. }
  65. forall(predicate) {
  66. return !this.tag || predicate(this.value);
  67. }
  68. filter(predicate) {
  69. if (!this.tag || predicate(this.value)) {
  70. return this;
  71. } else {
  72. return Optional.none();
  73. }
  74. }
  75. getOr(replacement) {
  76. return this.tag ? this.value : replacement;
  77. }
  78. or(replacement) {
  79. return this.tag ? this : replacement;
  80. }
  81. getOrThunk(thunk) {
  82. return this.tag ? this.value : thunk();
  83. }
  84. orThunk(thunk) {
  85. return this.tag ? this : thunk();
  86. }
  87. getOrDie(message) {
  88. if (!this.tag) {
  89. throw new Error(message !== null && message !== void 0 ? message : 'Called getOrDie on None');
  90. } else {
  91. return this.value;
  92. }
  93. }
  94. static from(value) {
  95. return isNonNullable(value) ? Optional.some(value) : Optional.none();
  96. }
  97. getOrNull() {
  98. return this.tag ? this.value : null;
  99. }
  100. getOrUndefined() {
  101. return this.value;
  102. }
  103. each(worker) {
  104. if (this.tag) {
  105. worker(this.value);
  106. }
  107. }
  108. toArray() {
  109. return this.tag ? [this.value] : [];
  110. }
  111. toString() {
  112. return this.tag ? `some(${ this.value })` : 'none()';
  113. }
  114. }
  115. Optional.singletonNone = new Optional(false);
  116. const get$1 = (xs, i) => i >= 0 && i < xs.length ? Optional.some(xs[i]) : Optional.none();
  117. const head = xs => get$1(xs, 0);
  118. var global$1 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
  119. const Global = typeof window !== 'undefined' ? window : Function('return this;')();
  120. const prismjs = function (global, module, exports) {
  121. const oldprism = window.Prism;
  122. window.Prism = { manual: true };
  123. var _self = typeof window !== 'undefined' ? window : typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope ? self : {};
  124. var Prism = function (_self) {
  125. var lang = /(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i;
  126. var uniqueId = 0;
  127. var plainTextGrammar = {};
  128. var _ = {
  129. manual: _self.Prism && _self.Prism.manual,
  130. disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler,
  131. util: {
  132. encode: function encode(tokens) {
  133. if (tokens instanceof Token) {
  134. return new Token(tokens.type, encode(tokens.content), tokens.alias);
  135. } else if (Array.isArray(tokens)) {
  136. return tokens.map(encode);
  137. } else {
  138. return tokens.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/\u00a0/g, ' ');
  139. }
  140. },
  141. type: function (o) {
  142. return Object.prototype.toString.call(o).slice(8, -1);
  143. },
  144. objId: function (obj) {
  145. if (!obj['__id']) {
  146. Object.defineProperty(obj, '__id', { value: ++uniqueId });
  147. }
  148. return obj['__id'];
  149. },
  150. clone: function deepClone(o, visited) {
  151. visited = visited || {};
  152. var clone;
  153. var id;
  154. switch (_.util.type(o)) {
  155. case 'Object':
  156. id = _.util.objId(o);
  157. if (visited[id]) {
  158. return visited[id];
  159. }
  160. clone = {};
  161. visited[id] = clone;
  162. for (var key in o) {
  163. if (o.hasOwnProperty(key)) {
  164. clone[key] = deepClone(o[key], visited);
  165. }
  166. }
  167. return clone;
  168. case 'Array':
  169. id = _.util.objId(o);
  170. if (visited[id]) {
  171. return visited[id];
  172. }
  173. clone = [];
  174. visited[id] = clone;
  175. o.forEach(function (v, i) {
  176. clone[i] = deepClone(v, visited);
  177. });
  178. return clone;
  179. default:
  180. return o;
  181. }
  182. },
  183. getLanguage: function (element) {
  184. while (element) {
  185. var m = lang.exec(element.className);
  186. if (m) {
  187. return m[1].toLowerCase();
  188. }
  189. element = element.parentElement;
  190. }
  191. return 'none';
  192. },
  193. setLanguage: function (element, language) {
  194. element.className = element.className.replace(RegExp(lang, 'gi'), '');
  195. element.classList.add('language-' + language);
  196. },
  197. currentScript: function () {
  198. if (typeof document === 'undefined') {
  199. return null;
  200. }
  201. if ('currentScript' in document && 1 < 2) {
  202. return document.currentScript;
  203. }
  204. try {
  205. throw new Error();
  206. } catch (err) {
  207. var src = (/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(err.stack) || [])[1];
  208. if (src) {
  209. var scripts = document.getElementsByTagName('script');
  210. for (var i in scripts) {
  211. if (scripts[i].src == src) {
  212. return scripts[i];
  213. }
  214. }
  215. }
  216. return null;
  217. }
  218. },
  219. isActive: function (element, className, defaultActivation) {
  220. var no = 'no-' + className;
  221. while (element) {
  222. var classList = element.classList;
  223. if (classList.contains(className)) {
  224. return true;
  225. }
  226. if (classList.contains(no)) {
  227. return false;
  228. }
  229. element = element.parentElement;
  230. }
  231. return !!defaultActivation;
  232. }
  233. },
  234. languages: {
  235. plain: plainTextGrammar,
  236. plaintext: plainTextGrammar,
  237. text: plainTextGrammar,
  238. txt: plainTextGrammar,
  239. extend: function (id, redef) {
  240. var lang = _.util.clone(_.languages[id]);
  241. for (var key in redef) {
  242. lang[key] = redef[key];
  243. }
  244. return lang;
  245. },
  246. insertBefore: function (inside, before, insert, root) {
  247. root = root || _.languages;
  248. var grammar = root[inside];
  249. var ret = {};
  250. for (var token in grammar) {
  251. if (grammar.hasOwnProperty(token)) {
  252. if (token == before) {
  253. for (var newToken in insert) {
  254. if (insert.hasOwnProperty(newToken)) {
  255. ret[newToken] = insert[newToken];
  256. }
  257. }
  258. }
  259. if (!insert.hasOwnProperty(token)) {
  260. ret[token] = grammar[token];
  261. }
  262. }
  263. }
  264. var old = root[inside];
  265. root[inside] = ret;
  266. _.languages.DFS(_.languages, function (key, value) {
  267. if (value === old && key != inside) {
  268. this[key] = ret;
  269. }
  270. });
  271. return ret;
  272. },
  273. DFS: function DFS(o, callback, type, visited) {
  274. visited = visited || {};
  275. var objId = _.util.objId;
  276. for (var i in o) {
  277. if (o.hasOwnProperty(i)) {
  278. callback.call(o, i, o[i], type || i);
  279. var property = o[i];
  280. var propertyType = _.util.type(property);
  281. if (propertyType === 'Object' && !visited[objId(property)]) {
  282. visited[objId(property)] = true;
  283. DFS(property, callback, null, visited);
  284. } else if (propertyType === 'Array' && !visited[objId(property)]) {
  285. visited[objId(property)] = true;
  286. DFS(property, callback, i, visited);
  287. }
  288. }
  289. }
  290. }
  291. },
  292. plugins: {},
  293. highlightAll: function (async, callback) {
  294. _.highlightAllUnder(document, async, callback);
  295. },
  296. highlightAllUnder: function (container, async, callback) {
  297. var env = {
  298. callback: callback,
  299. container: container,
  300. selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
  301. };
  302. _.hooks.run('before-highlightall', env);
  303. env.elements = Array.prototype.slice.apply(env.container.querySelectorAll(env.selector));
  304. _.hooks.run('before-all-elements-highlight', env);
  305. for (var i = 0, element; element = env.elements[i++];) {
  306. _.highlightElement(element, async === true, env.callback);
  307. }
  308. },
  309. highlightElement: function (element, async, callback) {
  310. var language = _.util.getLanguage(element);
  311. var grammar = _.languages[language];
  312. _.util.setLanguage(element, language);
  313. var parent = element.parentElement;
  314. if (parent && parent.nodeName.toLowerCase() === 'pre') {
  315. _.util.setLanguage(parent, language);
  316. }
  317. var code = element.textContent;
  318. var env = {
  319. element: element,
  320. language: language,
  321. grammar: grammar,
  322. code: code
  323. };
  324. function insertHighlightedCode(highlightedCode) {
  325. env.highlightedCode = highlightedCode;
  326. _.hooks.run('before-insert', env);
  327. env.element.innerHTML = env.highlightedCode;
  328. _.hooks.run('after-highlight', env);
  329. _.hooks.run('complete', env);
  330. callback && callback.call(env.element);
  331. }
  332. _.hooks.run('before-sanity-check', env);
  333. parent = env.element.parentElement;
  334. if (parent && parent.nodeName.toLowerCase() === 'pre' && !parent.hasAttribute('tabindex')) {
  335. parent.setAttribute('tabindex', '0');
  336. }
  337. if (!env.code) {
  338. _.hooks.run('complete', env);
  339. callback && callback.call(env.element);
  340. return;
  341. }
  342. _.hooks.run('before-highlight', env);
  343. if (!env.grammar) {
  344. insertHighlightedCode(_.util.encode(env.code));
  345. return;
  346. }
  347. if (async && _self.Worker) {
  348. var worker = new Worker(_.filename);
  349. worker.onmessage = function (evt) {
  350. insertHighlightedCode(evt.data);
  351. };
  352. worker.postMessage(JSON.stringify({
  353. language: env.language,
  354. code: env.code,
  355. immediateClose: true
  356. }));
  357. } else {
  358. insertHighlightedCode(_.highlight(env.code, env.grammar, env.language));
  359. }
  360. },
  361. highlight: function (text, grammar, language) {
  362. var env = {
  363. code: text,
  364. grammar: grammar,
  365. language: language
  366. };
  367. _.hooks.run('before-tokenize', env);
  368. if (!env.grammar) {
  369. throw new Error('The language "' + env.language + '" has no grammar.');
  370. }
  371. env.tokens = _.tokenize(env.code, env.grammar);
  372. _.hooks.run('after-tokenize', env);
  373. return Token.stringify(_.util.encode(env.tokens), env.language);
  374. },
  375. tokenize: function (text, grammar) {
  376. var rest = grammar.rest;
  377. if (rest) {
  378. for (var token in rest) {
  379. grammar[token] = rest[token];
  380. }
  381. delete grammar.rest;
  382. }
  383. var tokenList = new LinkedList();
  384. addAfter(tokenList, tokenList.head, text);
  385. matchGrammar(text, tokenList, grammar, tokenList.head, 0);
  386. return toArray(tokenList);
  387. },
  388. hooks: {
  389. all: {},
  390. add: function (name, callback) {
  391. var hooks = _.hooks.all;
  392. hooks[name] = hooks[name] || [];
  393. hooks[name].push(callback);
  394. },
  395. run: function (name, env) {
  396. var callbacks = _.hooks.all[name];
  397. if (!callbacks || !callbacks.length) {
  398. return;
  399. }
  400. for (var i = 0, callback; callback = callbacks[i++];) {
  401. callback(env);
  402. }
  403. }
  404. },
  405. Token: Token
  406. };
  407. _self.Prism = _;
  408. function Token(type, content, alias, matchedStr) {
  409. this.type = type;
  410. this.content = content;
  411. this.alias = alias;
  412. this.length = (matchedStr || '').length | 0;
  413. }
  414. Token.stringify = function stringify(o, language) {
  415. if (typeof o == 'string') {
  416. return o;
  417. }
  418. if (Array.isArray(o)) {
  419. var s = '';
  420. o.forEach(function (e) {
  421. s += stringify(e, language);
  422. });
  423. return s;
  424. }
  425. var env = {
  426. type: o.type,
  427. content: stringify(o.content, language),
  428. tag: 'span',
  429. classes: [
  430. 'token',
  431. o.type
  432. ],
  433. attributes: {},
  434. language: language
  435. };
  436. var aliases = o.alias;
  437. if (aliases) {
  438. if (Array.isArray(aliases)) {
  439. Array.prototype.push.apply(env.classes, aliases);
  440. } else {
  441. env.classes.push(aliases);
  442. }
  443. }
  444. _.hooks.run('wrap', env);
  445. var attributes = '';
  446. for (var name in env.attributes) {
  447. attributes += ' ' + name + '="' + (env.attributes[name] || '').replace(/"/g, '&quot;') + '"';
  448. }
  449. return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + attributes + '>' + env.content + '</' + env.tag + '>';
  450. };
  451. function matchPattern(pattern, pos, text, lookbehind) {
  452. pattern.lastIndex = pos;
  453. var match = pattern.exec(text);
  454. if (match && lookbehind && match[1]) {
  455. var lookbehindLength = match[1].length;
  456. match.index += lookbehindLength;
  457. match[0] = match[0].slice(lookbehindLength);
  458. }
  459. return match;
  460. }
  461. function matchGrammar(text, tokenList, grammar, startNode, startPos, rematch) {
  462. for (var token in grammar) {
  463. if (!grammar.hasOwnProperty(token) || !grammar[token]) {
  464. continue;
  465. }
  466. var patterns = grammar[token];
  467. patterns = Array.isArray(patterns) ? patterns : [patterns];
  468. for (var j = 0; j < patterns.length; ++j) {
  469. if (rematch && rematch.cause == token + ',' + j) {
  470. return;
  471. }
  472. var patternObj = patterns[j];
  473. var inside = patternObj.inside;
  474. var lookbehind = !!patternObj.lookbehind;
  475. var greedy = !!patternObj.greedy;
  476. var alias = patternObj.alias;
  477. if (greedy && !patternObj.pattern.global) {
  478. var flags = patternObj.pattern.toString().match(/[imsuy]*$/)[0];
  479. patternObj.pattern = RegExp(patternObj.pattern.source, flags + 'g');
  480. }
  481. var pattern = patternObj.pattern || patternObj;
  482. for (var currentNode = startNode.next, pos = startPos; currentNode !== tokenList.tail; pos += currentNode.value.length, currentNode = currentNode.next) {
  483. if (rematch && pos >= rematch.reach) {
  484. break;
  485. }
  486. var str = currentNode.value;
  487. if (tokenList.length > text.length) {
  488. return;
  489. }
  490. if (str instanceof Token) {
  491. continue;
  492. }
  493. var removeCount = 1;
  494. var match;
  495. if (greedy) {
  496. match = matchPattern(pattern, pos, text, lookbehind);
  497. if (!match || match.index >= text.length) {
  498. break;
  499. }
  500. var from = match.index;
  501. var to = match.index + match[0].length;
  502. var p = pos;
  503. p += currentNode.value.length;
  504. while (from >= p) {
  505. currentNode = currentNode.next;
  506. p += currentNode.value.length;
  507. }
  508. p -= currentNode.value.length;
  509. pos = p;
  510. if (currentNode.value instanceof Token) {
  511. continue;
  512. }
  513. for (var k = currentNode; k !== tokenList.tail && (p < to || typeof k.value === 'string'); k = k.next) {
  514. removeCount++;
  515. p += k.value.length;
  516. }
  517. removeCount--;
  518. str = text.slice(pos, p);
  519. match.index -= pos;
  520. } else {
  521. match = matchPattern(pattern, 0, str, lookbehind);
  522. if (!match) {
  523. continue;
  524. }
  525. }
  526. var from = match.index;
  527. var matchStr = match[0];
  528. var before = str.slice(0, from);
  529. var after = str.slice(from + matchStr.length);
  530. var reach = pos + str.length;
  531. if (rematch && reach > rematch.reach) {
  532. rematch.reach = reach;
  533. }
  534. var removeFrom = currentNode.prev;
  535. if (before) {
  536. removeFrom = addAfter(tokenList, removeFrom, before);
  537. pos += before.length;
  538. }
  539. removeRange(tokenList, removeFrom, removeCount);
  540. var wrapped = new Token(token, inside ? _.tokenize(matchStr, inside) : matchStr, alias, matchStr);
  541. currentNode = addAfter(tokenList, removeFrom, wrapped);
  542. if (after) {
  543. addAfter(tokenList, currentNode, after);
  544. }
  545. if (removeCount > 1) {
  546. var nestedRematch = {
  547. cause: token + ',' + j,
  548. reach: reach
  549. };
  550. matchGrammar(text, tokenList, grammar, currentNode.prev, pos, nestedRematch);
  551. if (rematch && nestedRematch.reach > rematch.reach) {
  552. rematch.reach = nestedRematch.reach;
  553. }
  554. }
  555. }
  556. }
  557. }
  558. }
  559. function LinkedList() {
  560. var head = {
  561. value: null,
  562. prev: null,
  563. next: null
  564. };
  565. var tail = {
  566. value: null,
  567. prev: head,
  568. next: null
  569. };
  570. head.next = tail;
  571. this.head = head;
  572. this.tail = tail;
  573. this.length = 0;
  574. }
  575. function addAfter(list, node, value) {
  576. var next = node.next;
  577. var newNode = {
  578. value: value,
  579. prev: node,
  580. next: next
  581. };
  582. node.next = newNode;
  583. next.prev = newNode;
  584. list.length++;
  585. return newNode;
  586. }
  587. function removeRange(list, node, count) {
  588. var next = node.next;
  589. for (var i = 0; i < count && next !== list.tail; i++) {
  590. next = next.next;
  591. }
  592. node.next = next;
  593. next.prev = node;
  594. list.length -= i;
  595. }
  596. function toArray(list) {
  597. var array = [];
  598. var node = list.head.next;
  599. while (node !== list.tail) {
  600. array.push(node.value);
  601. node = node.next;
  602. }
  603. return array;
  604. }
  605. if (!_self.document) {
  606. if (!_self.addEventListener) {
  607. return _;
  608. }
  609. if (!_.disableWorkerMessageHandler) {
  610. _self.addEventListener('message', function (evt) {
  611. var message = JSON.parse(evt.data);
  612. var lang = message.language;
  613. var code = message.code;
  614. var immediateClose = message.immediateClose;
  615. _self.postMessage(_.highlight(code, _.languages[lang], lang));
  616. if (immediateClose) {
  617. _self.close();
  618. }
  619. }, false);
  620. }
  621. return _;
  622. }
  623. var script = _.util.currentScript();
  624. if (script) {
  625. _.filename = script.src;
  626. if (script.hasAttribute('data-manual')) {
  627. _.manual = true;
  628. }
  629. }
  630. function highlightAutomaticallyCallback() {
  631. if (!_.manual) {
  632. _.highlightAll();
  633. }
  634. }
  635. if (!_.manual) {
  636. var readyState = document.readyState;
  637. if (readyState === 'loading' || readyState === 'interactive' && script && script.defer) {
  638. document.addEventListener('DOMContentLoaded', highlightAutomaticallyCallback);
  639. } else {
  640. if (window.requestAnimationFrame) {
  641. window.requestAnimationFrame(highlightAutomaticallyCallback);
  642. } else {
  643. window.setTimeout(highlightAutomaticallyCallback, 16);
  644. }
  645. }
  646. }
  647. return _;
  648. }(_self);
  649. if (typeof module !== 'undefined' && module.exports) {
  650. module.exports = Prism;
  651. }
  652. if (typeof global !== 'undefined') {
  653. global.Prism = Prism;
  654. }
  655. Prism.languages.clike = {
  656. 'comment': [
  657. {
  658. pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
  659. lookbehind: true,
  660. greedy: true
  661. },
  662. {
  663. pattern: /(^|[^\\:])\/\/.*/,
  664. lookbehind: true,
  665. greedy: true
  666. }
  667. ],
  668. 'string': {
  669. pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
  670. greedy: true
  671. },
  672. 'class-name': {
  673. pattern: /(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i,
  674. lookbehind: true,
  675. inside: { 'punctuation': /[.\\]/ }
  676. },
  677. 'keyword': /\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,
  678. 'boolean': /\b(?:false|true)\b/,
  679. 'function': /\b\w+(?=\()/,
  680. 'number': /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
  681. 'operator': /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
  682. 'punctuation': /[{}[\];(),.:]/
  683. };
  684. (function (Prism) {
  685. function getPlaceholder(language, index) {
  686. return '___' + language.toUpperCase() + index + '___';
  687. }
  688. Object.defineProperties(Prism.languages['markup-templating'] = {}, {
  689. buildPlaceholders: {
  690. value: function (env, language, placeholderPattern, replaceFilter) {
  691. if (env.language !== language) {
  692. return;
  693. }
  694. var tokenStack = env.tokenStack = [];
  695. env.code = env.code.replace(placeholderPattern, function (match) {
  696. if (typeof replaceFilter === 'function' && !replaceFilter(match)) {
  697. return match;
  698. }
  699. var i = tokenStack.length;
  700. var placeholder;
  701. while (env.code.indexOf(placeholder = getPlaceholder(language, i)) !== -1) {
  702. ++i;
  703. }
  704. tokenStack[i] = match;
  705. return placeholder;
  706. });
  707. env.grammar = Prism.languages.markup;
  708. }
  709. },
  710. tokenizePlaceholders: {
  711. value: function (env, language) {
  712. if (env.language !== language || !env.tokenStack) {
  713. return;
  714. }
  715. env.grammar = Prism.languages[language];
  716. var j = 0;
  717. var keys = Object.keys(env.tokenStack);
  718. function walkTokens(tokens) {
  719. for (var i = 0; i < tokens.length; i++) {
  720. if (j >= keys.length) {
  721. break;
  722. }
  723. var token = tokens[i];
  724. if (typeof token === 'string' || token.content && typeof token.content === 'string') {
  725. var k = keys[j];
  726. var t = env.tokenStack[k];
  727. var s = typeof token === 'string' ? token : token.content;
  728. var placeholder = getPlaceholder(language, k);
  729. var index = s.indexOf(placeholder);
  730. if (index > -1) {
  731. ++j;
  732. var before = s.substring(0, index);
  733. var middle = new Prism.Token(language, Prism.tokenize(t, env.grammar), 'language-' + language, t);
  734. var after = s.substring(index + placeholder.length);
  735. var replacement = [];
  736. if (before) {
  737. replacement.push.apply(replacement, walkTokens([before]));
  738. }
  739. replacement.push(middle);
  740. if (after) {
  741. replacement.push.apply(replacement, walkTokens([after]));
  742. }
  743. if (typeof token === 'string') {
  744. tokens.splice.apply(tokens, [
  745. i,
  746. 1
  747. ].concat(replacement));
  748. } else {
  749. token.content = replacement;
  750. }
  751. }
  752. } else if (token.content) {
  753. walkTokens(token.content);
  754. }
  755. }
  756. return tokens;
  757. }
  758. walkTokens(env.tokens);
  759. }
  760. }
  761. });
  762. }(Prism));
  763. Prism.languages.c = Prism.languages.extend('clike', {
  764. 'comment': {
  765. pattern: /\/\/(?:[^\r\n\\]|\\(?:\r\n?|\n|(?![\r\n])))*|\/\*[\s\S]*?(?:\*\/|$)/,
  766. greedy: true
  767. },
  768. 'string': {
  769. pattern: /"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/,
  770. greedy: true
  771. },
  772. 'class-name': {
  773. pattern: /(\b(?:enum|struct)\s+(?:__attribute__\s*\(\([\s\S]*?\)\)\s*)?)\w+|\b[a-z]\w*_t\b/,
  774. lookbehind: true
  775. },
  776. 'keyword': /\b(?:_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|__attribute__|asm|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|inline|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|typeof|union|unsigned|void|volatile|while)\b/,
  777. 'function': /\b[a-z_]\w*(?=\s*\()/i,
  778. 'number': /(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i,
  779. 'operator': />>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/
  780. });
  781. Prism.languages.insertBefore('c', 'string', {
  782. 'char': {
  783. pattern: /'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n]){0,32}'/,
  784. greedy: true
  785. }
  786. });
  787. Prism.languages.insertBefore('c', 'string', {
  788. 'macro': {
  789. pattern: /(^[\t ]*)#\s*[a-z](?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im,
  790. lookbehind: true,
  791. greedy: true,
  792. alias: 'property',
  793. inside: {
  794. 'string': [
  795. {
  796. pattern: /^(#\s*include\s*)<[^>]+>/,
  797. lookbehind: true
  798. },
  799. Prism.languages.c['string']
  800. ],
  801. 'char': Prism.languages.c['char'],
  802. 'comment': Prism.languages.c['comment'],
  803. 'macro-name': [
  804. {
  805. pattern: /(^#\s*define\s+)\w+\b(?!\()/i,
  806. lookbehind: true
  807. },
  808. {
  809. pattern: /(^#\s*define\s+)\w+\b(?=\()/i,
  810. lookbehind: true,
  811. alias: 'function'
  812. }
  813. ],
  814. 'directive': {
  815. pattern: /^(#\s*)[a-z]+/,
  816. lookbehind: true,
  817. alias: 'keyword'
  818. },
  819. 'directive-hash': /^#/,
  820. 'punctuation': /##|\\(?=[\r\n])/,
  821. 'expression': {
  822. pattern: /\S[\s\S]*/,
  823. inside: Prism.languages.c
  824. }
  825. }
  826. }
  827. });
  828. Prism.languages.insertBefore('c', 'function', { 'constant': /\b(?:EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|__DATE__|__FILE__|__LINE__|__TIMESTAMP__|__TIME__|__func__|stderr|stdin|stdout)\b/ });
  829. delete Prism.languages.c['boolean'];
  830. (function (Prism) {
  831. var keyword = /\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char16_t|char32_t|char8_t|class|co_await|co_return|co_yield|compl|concept|const|const_cast|consteval|constexpr|constinit|continue|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|final|float|for|friend|goto|if|import|inline|int|int16_t|int32_t|int64_t|int8_t|long|module|mutable|namespace|new|noexcept|nullptr|operator|override|private|protected|public|register|reinterpret_cast|requires|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|uint16_t|uint32_t|uint64_t|uint8_t|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/;
  832. var modName = /\b(?!<keyword>)\w+(?:\s*\.\s*\w+)*\b/.source.replace(/<keyword>/g, function () {
  833. return keyword.source;
  834. });
  835. Prism.languages.cpp = Prism.languages.extend('c', {
  836. 'class-name': [
  837. {
  838. pattern: RegExp(/(\b(?:class|concept|enum|struct|typename)\s+)(?!<keyword>)\w+/.source.replace(/<keyword>/g, function () {
  839. return keyword.source;
  840. })),
  841. lookbehind: true
  842. },
  843. /\b[A-Z]\w*(?=\s*::\s*\w+\s*\()/,
  844. /\b[A-Z_]\w*(?=\s*::\s*~\w+\s*\()/i,
  845. /\b\w+(?=\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*::\s*\w+\s*\()/
  846. ],
  847. 'keyword': keyword,
  848. 'number': {
  849. pattern: /(?:\b0b[01']+|\b0x(?:[\da-f']+(?:\.[\da-f']*)?|\.[\da-f']+)(?:p[+-]?[\d']+)?|(?:\b[\d']+(?:\.[\d']*)?|\B\.[\d']+)(?:e[+-]?[\d']+)?)[ful]{0,4}/i,
  850. greedy: true
  851. },
  852. 'operator': />>=?|<<=?|->|--|\+\+|&&|\|\||[?:~]|<=>|[-+*/%&|^!=<>]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/,
  853. 'boolean': /\b(?:false|true)\b/
  854. });
  855. Prism.languages.insertBefore('cpp', 'string', {
  856. 'module': {
  857. pattern: RegExp(/(\b(?:import|module)\s+)/.source + '(?:' + /"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|<[^<>\r\n]*>/.source + '|' + /<mod-name>(?:\s*:\s*<mod-name>)?|:\s*<mod-name>/.source.replace(/<mod-name>/g, function () {
  858. return modName;
  859. }) + ')'),
  860. lookbehind: true,
  861. greedy: true,
  862. inside: {
  863. 'string': /^[<"][\s\S]+/,
  864. 'operator': /:/,
  865. 'punctuation': /\./
  866. }
  867. },
  868. 'raw-string': {
  869. pattern: /R"([^()\\ ]{0,16})\([\s\S]*?\)\1"/,
  870. alias: 'string',
  871. greedy: true
  872. }
  873. });
  874. Prism.languages.insertBefore('cpp', 'keyword', {
  875. 'generic-function': {
  876. pattern: /\b(?!operator\b)[a-z_]\w*\s*<(?:[^<>]|<[^<>]*>)*>(?=\s*\()/i,
  877. inside: {
  878. 'function': /^\w+/,
  879. 'generic': {
  880. pattern: /<[\s\S]+/,
  881. alias: 'class-name',
  882. inside: Prism.languages.cpp
  883. }
  884. }
  885. }
  886. });
  887. Prism.languages.insertBefore('cpp', 'operator', {
  888. 'double-colon': {
  889. pattern: /::/,
  890. alias: 'punctuation'
  891. }
  892. });
  893. Prism.languages.insertBefore('cpp', 'class-name', {
  894. 'base-clause': {
  895. pattern: /(\b(?:class|struct)\s+\w+\s*:\s*)[^;{}"'\s]+(?:\s+[^;{}"'\s]+)*(?=\s*[;{])/,
  896. lookbehind: true,
  897. greedy: true,
  898. inside: Prism.languages.extend('cpp', {})
  899. }
  900. });
  901. Prism.languages.insertBefore('inside', 'double-colon', { 'class-name': /\b[a-z_]\w*\b(?!\s*::)/i }, Prism.languages.cpp['base-clause']);
  902. }(Prism));
  903. (function (Prism) {
  904. function replace(pattern, replacements) {
  905. return pattern.replace(/<<(\d+)>>/g, function (m, index) {
  906. return '(?:' + replacements[+index] + ')';
  907. });
  908. }
  909. function re(pattern, replacements, flags) {
  910. return RegExp(replace(pattern, replacements), flags || '');
  911. }
  912. function nested(pattern, depthLog2) {
  913. for (var i = 0; i < depthLog2; i++) {
  914. pattern = pattern.replace(/<<self>>/g, function () {
  915. return '(?:' + pattern + ')';
  916. });
  917. }
  918. return pattern.replace(/<<self>>/g, '[^\\s\\S]');
  919. }
  920. var keywordKinds = {
  921. type: 'bool byte char decimal double dynamic float int long object sbyte short string uint ulong ushort var void',
  922. typeDeclaration: 'class enum interface record struct',
  923. contextual: 'add alias and ascending async await by descending from(?=\\s*(?:\\w|$)) get global group into init(?=\\s*;) join let nameof not notnull on or orderby partial remove select set unmanaged value when where with(?=\\s*{)',
  924. other: 'abstract as base break case catch checked const continue default delegate do else event explicit extern finally fixed for foreach goto if implicit in internal is lock namespace new null operator out override params private protected public readonly ref return sealed sizeof stackalloc static switch this throw try typeof unchecked unsafe using virtual volatile while yield'
  925. };
  926. function keywordsToPattern(words) {
  927. return '\\b(?:' + words.trim().replace(/ /g, '|') + ')\\b';
  928. }
  929. var typeDeclarationKeywords = keywordsToPattern(keywordKinds.typeDeclaration);
  930. var keywords = RegExp(keywordsToPattern(keywordKinds.type + ' ' + keywordKinds.typeDeclaration + ' ' + keywordKinds.contextual + ' ' + keywordKinds.other));
  931. var nonTypeKeywords = keywordsToPattern(keywordKinds.typeDeclaration + ' ' + keywordKinds.contextual + ' ' + keywordKinds.other);
  932. var nonContextualKeywords = keywordsToPattern(keywordKinds.type + ' ' + keywordKinds.typeDeclaration + ' ' + keywordKinds.other);
  933. var generic = nested(/<(?:[^<>;=+\-*/%&|^]|<<self>>)*>/.source, 2);
  934. var nestedRound = nested(/\((?:[^()]|<<self>>)*\)/.source, 2);
  935. var name = /@?\b[A-Za-z_]\w*\b/.source;
  936. var genericName = replace(/<<0>>(?:\s*<<1>>)?/.source, [
  937. name,
  938. generic
  939. ]);
  940. var identifier = replace(/(?!<<0>>)<<1>>(?:\s*\.\s*<<1>>)*/.source, [
  941. nonTypeKeywords,
  942. genericName
  943. ]);
  944. var array = /\[\s*(?:,\s*)*\]/.source;
  945. var typeExpressionWithoutTuple = replace(/<<0>>(?:\s*(?:\?\s*)?<<1>>)*(?:\s*\?)?/.source, [
  946. identifier,
  947. array
  948. ]);
  949. var tupleElement = replace(/[^,()<>[\];=+\-*/%&|^]|<<0>>|<<1>>|<<2>>/.source, [
  950. generic,
  951. nestedRound,
  952. array
  953. ]);
  954. var tuple = replace(/\(<<0>>+(?:,<<0>>+)+\)/.source, [tupleElement]);
  955. var typeExpression = replace(/(?:<<0>>|<<1>>)(?:\s*(?:\?\s*)?<<2>>)*(?:\s*\?)?/.source, [
  956. tuple,
  957. identifier,
  958. array
  959. ]);
  960. var typeInside = {
  961. 'keyword': keywords,
  962. 'punctuation': /[<>()?,.:[\]]/
  963. };
  964. var character = /'(?:[^\r\n'\\]|\\.|\\[Uux][\da-fA-F]{1,8})'/.source;
  965. var regularString = /"(?:\\.|[^\\"\r\n])*"/.source;
  966. var verbatimString = /@"(?:""|\\[\s\S]|[^\\"])*"(?!")/.source;
  967. Prism.languages.csharp = Prism.languages.extend('clike', {
  968. 'string': [
  969. {
  970. pattern: re(/(^|[^$\\])<<0>>/.source, [verbatimString]),
  971. lookbehind: true,
  972. greedy: true
  973. },
  974. {
  975. pattern: re(/(^|[^@$\\])<<0>>/.source, [regularString]),
  976. lookbehind: true,
  977. greedy: true
  978. }
  979. ],
  980. 'class-name': [
  981. {
  982. pattern: re(/(\busing\s+static\s+)<<0>>(?=\s*;)/.source, [identifier]),
  983. lookbehind: true,
  984. inside: typeInside
  985. },
  986. {
  987. pattern: re(/(\busing\s+<<0>>\s*=\s*)<<1>>(?=\s*;)/.source, [
  988. name,
  989. typeExpression
  990. ]),
  991. lookbehind: true,
  992. inside: typeInside
  993. },
  994. {
  995. pattern: re(/(\busing\s+)<<0>>(?=\s*=)/.source, [name]),
  996. lookbehind: true
  997. },
  998. {
  999. pattern: re(/(\b<<0>>\s+)<<1>>/.source, [
  1000. typeDeclarationKeywords,
  1001. genericName
  1002. ]),
  1003. lookbehind: true,
  1004. inside: typeInside
  1005. },
  1006. {
  1007. pattern: re(/(\bcatch\s*\(\s*)<<0>>/.source, [identifier]),
  1008. lookbehind: true,
  1009. inside: typeInside
  1010. },
  1011. {
  1012. pattern: re(/(\bwhere\s+)<<0>>/.source, [name]),
  1013. lookbehind: true
  1014. },
  1015. {
  1016. pattern: re(/(\b(?:is(?:\s+not)?|as)\s+)<<0>>/.source, [typeExpressionWithoutTuple]),
  1017. lookbehind: true,
  1018. inside: typeInside
  1019. },
  1020. {
  1021. pattern: re(/\b<<0>>(?=\s+(?!<<1>>|with\s*\{)<<2>>(?:\s*[=,;:{)\]]|\s+(?:in|when)\b))/.source, [
  1022. typeExpression,
  1023. nonContextualKeywords,
  1024. name
  1025. ]),
  1026. inside: typeInside
  1027. }
  1028. ],
  1029. 'keyword': keywords,
  1030. 'number': /(?:\b0(?:x[\da-f_]*[\da-f]|b[01_]*[01])|(?:\B\.\d+(?:_+\d+)*|\b\d+(?:_+\d+)*(?:\.\d+(?:_+\d+)*)?)(?:e[-+]?\d+(?:_+\d+)*)?)(?:[dflmu]|lu|ul)?\b/i,
  1031. 'operator': />>=?|<<=?|[-=]>|([-+&|])\1|~|\?\?=?|[-+*/%&|^!=<>]=?/,
  1032. 'punctuation': /\?\.?|::|[{}[\];(),.:]/
  1033. });
  1034. Prism.languages.insertBefore('csharp', 'number', {
  1035. 'range': {
  1036. pattern: /\.\./,
  1037. alias: 'operator'
  1038. }
  1039. });
  1040. Prism.languages.insertBefore('csharp', 'punctuation', {
  1041. 'named-parameter': {
  1042. pattern: re(/([(,]\s*)<<0>>(?=\s*:)/.source, [name]),
  1043. lookbehind: true,
  1044. alias: 'punctuation'
  1045. }
  1046. });
  1047. Prism.languages.insertBefore('csharp', 'class-name', {
  1048. 'namespace': {
  1049. pattern: re(/(\b(?:namespace|using)\s+)<<0>>(?:\s*\.\s*<<0>>)*(?=\s*[;{])/.source, [name]),
  1050. lookbehind: true,
  1051. inside: { 'punctuation': /\./ }
  1052. },
  1053. 'type-expression': {
  1054. pattern: re(/(\b(?:default|sizeof|typeof)\s*\(\s*(?!\s))(?:[^()\s]|\s(?!\s)|<<0>>)*(?=\s*\))/.source, [nestedRound]),
  1055. lookbehind: true,
  1056. alias: 'class-name',
  1057. inside: typeInside
  1058. },
  1059. 'return-type': {
  1060. pattern: re(/<<0>>(?=\s+(?:<<1>>\s*(?:=>|[({]|\.\s*this\s*\[)|this\s*\[))/.source, [
  1061. typeExpression,
  1062. identifier
  1063. ]),
  1064. inside: typeInside,
  1065. alias: 'class-name'
  1066. },
  1067. 'constructor-invocation': {
  1068. pattern: re(/(\bnew\s+)<<0>>(?=\s*[[({])/.source, [typeExpression]),
  1069. lookbehind: true,
  1070. inside: typeInside,
  1071. alias: 'class-name'
  1072. },
  1073. 'generic-method': {
  1074. pattern: re(/<<0>>\s*<<1>>(?=\s*\()/.source, [
  1075. name,
  1076. generic
  1077. ]),
  1078. inside: {
  1079. 'function': re(/^<<0>>/.source, [name]),
  1080. 'generic': {
  1081. pattern: RegExp(generic),
  1082. alias: 'class-name',
  1083. inside: typeInside
  1084. }
  1085. }
  1086. },
  1087. 'type-list': {
  1088. pattern: re(/\b((?:<<0>>\s+<<1>>|record\s+<<1>>\s*<<5>>|where\s+<<2>>)\s*:\s*)(?:<<3>>|<<4>>|<<1>>\s*<<5>>|<<6>>)(?:\s*,\s*(?:<<3>>|<<4>>|<<6>>))*(?=\s*(?:where|[{;]|=>|$))/.source, [
  1089. typeDeclarationKeywords,
  1090. genericName,
  1091. name,
  1092. typeExpression,
  1093. keywords.source,
  1094. nestedRound,
  1095. /\bnew\s*\(\s*\)/.source
  1096. ]),
  1097. lookbehind: true,
  1098. inside: {
  1099. 'record-arguments': {
  1100. pattern: re(/(^(?!new\s*\()<<0>>\s*)<<1>>/.source, [
  1101. genericName,
  1102. nestedRound
  1103. ]),
  1104. lookbehind: true,
  1105. greedy: true,
  1106. inside: Prism.languages.csharp
  1107. },
  1108. 'keyword': keywords,
  1109. 'class-name': {
  1110. pattern: RegExp(typeExpression),
  1111. greedy: true,
  1112. inside: typeInside
  1113. },
  1114. 'punctuation': /[,()]/
  1115. }
  1116. },
  1117. 'preprocessor': {
  1118. pattern: /(^[\t ]*)#.*/m,
  1119. lookbehind: true,
  1120. alias: 'property',
  1121. inside: {
  1122. 'directive': {
  1123. pattern: /(#)\b(?:define|elif|else|endif|endregion|error|if|line|nullable|pragma|region|undef|warning)\b/,
  1124. lookbehind: true,
  1125. alias: 'keyword'
  1126. }
  1127. }
  1128. }
  1129. });
  1130. var regularStringOrCharacter = regularString + '|' + character;
  1131. var regularStringCharacterOrComment = replace(/\/(?![*/])|\/\/[^\r\n]*[\r\n]|\/\*(?:[^*]|\*(?!\/))*\*\/|<<0>>/.source, [regularStringOrCharacter]);
  1132. var roundExpression = nested(replace(/[^"'/()]|<<0>>|\(<<self>>*\)/.source, [regularStringCharacterOrComment]), 2);
  1133. var attrTarget = /\b(?:assembly|event|field|method|module|param|property|return|type)\b/.source;
  1134. var attr = replace(/<<0>>(?:\s*\(<<1>>*\))?/.source, [
  1135. identifier,
  1136. roundExpression
  1137. ]);
  1138. Prism.languages.insertBefore('csharp', 'class-name', {
  1139. 'attribute': {
  1140. pattern: re(/((?:^|[^\s\w>)?])\s*\[\s*)(?:<<0>>\s*:\s*)?<<1>>(?:\s*,\s*<<1>>)*(?=\s*\])/.source, [
  1141. attrTarget,
  1142. attr
  1143. ]),
  1144. lookbehind: true,
  1145. greedy: true,
  1146. inside: {
  1147. 'target': {
  1148. pattern: re(/^<<0>>(?=\s*:)/.source, [attrTarget]),
  1149. alias: 'keyword'
  1150. },
  1151. 'attribute-arguments': {
  1152. pattern: re(/\(<<0>>*\)/.source, [roundExpression]),
  1153. inside: Prism.languages.csharp
  1154. },
  1155. 'class-name': {
  1156. pattern: RegExp(identifier),
  1157. inside: { 'punctuation': /\./ }
  1158. },
  1159. 'punctuation': /[:,]/
  1160. }
  1161. }
  1162. });
  1163. var formatString = /:[^}\r\n]+/.source;
  1164. var mInterpolationRound = nested(replace(/[^"'/()]|<<0>>|\(<<self>>*\)/.source, [regularStringCharacterOrComment]), 2);
  1165. var mInterpolation = replace(/\{(?!\{)(?:(?![}:])<<0>>)*<<1>>?\}/.source, [
  1166. mInterpolationRound,
  1167. formatString
  1168. ]);
  1169. var sInterpolationRound = nested(replace(/[^"'/()]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|<<0>>|\(<<self>>*\)/.source, [regularStringOrCharacter]), 2);
  1170. var sInterpolation = replace(/\{(?!\{)(?:(?![}:])<<0>>)*<<1>>?\}/.source, [
  1171. sInterpolationRound,
  1172. formatString
  1173. ]);
  1174. function createInterpolationInside(interpolation, interpolationRound) {
  1175. return {
  1176. 'interpolation': {
  1177. pattern: re(/((?:^|[^{])(?:\{\{)*)<<0>>/.source, [interpolation]),
  1178. lookbehind: true,
  1179. inside: {
  1180. 'format-string': {
  1181. pattern: re(/(^\{(?:(?![}:])<<0>>)*)<<1>>(?=\}$)/.source, [
  1182. interpolationRound,
  1183. formatString
  1184. ]),
  1185. lookbehind: true,
  1186. inside: { 'punctuation': /^:/ }
  1187. },
  1188. 'punctuation': /^\{|\}$/,
  1189. 'expression': {
  1190. pattern: /[\s\S]+/,
  1191. alias: 'language-csharp',
  1192. inside: Prism.languages.csharp
  1193. }
  1194. }
  1195. },
  1196. 'string': /[\s\S]+/
  1197. };
  1198. }
  1199. Prism.languages.insertBefore('csharp', 'string', {
  1200. 'interpolation-string': [
  1201. {
  1202. pattern: re(/(^|[^\\])(?:\$@|@\$)"(?:""|\\[\s\S]|\{\{|<<0>>|[^\\{"])*"/.source, [mInterpolation]),
  1203. lookbehind: true,
  1204. greedy: true,
  1205. inside: createInterpolationInside(mInterpolation, mInterpolationRound)
  1206. },
  1207. {
  1208. pattern: re(/(^|[^@\\])\$"(?:\\.|\{\{|<<0>>|[^\\"{])*"/.source, [sInterpolation]),
  1209. lookbehind: true,
  1210. greedy: true,
  1211. inside: createInterpolationInside(sInterpolation, sInterpolationRound)
  1212. }
  1213. ],
  1214. 'char': {
  1215. pattern: RegExp(character),
  1216. greedy: true
  1217. }
  1218. });
  1219. Prism.languages.dotnet = Prism.languages.cs = Prism.languages.csharp;
  1220. }(Prism));
  1221. (function (Prism) {
  1222. var string = /(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;
  1223. Prism.languages.css = {
  1224. 'comment': /\/\*[\s\S]*?\*\//,
  1225. 'atrule': {
  1226. pattern: RegExp('@[\\w-](?:' + /[^;{\s"']|\s+(?!\s)/.source + '|' + string.source + ')*?' + /(?:;|(?=\s*\{))/.source),
  1227. inside: {
  1228. 'rule': /^@[\w-]+/,
  1229. 'selector-function-argument': {
  1230. pattern: /(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,
  1231. lookbehind: true,
  1232. alias: 'selector'
  1233. },
  1234. 'keyword': {
  1235. pattern: /(^|[^\w-])(?:and|not|only|or)(?![\w-])/,
  1236. lookbehind: true
  1237. }
  1238. }
  1239. },
  1240. 'url': {
  1241. pattern: RegExp('\\burl\\((?:' + string.source + '|' + /(?:[^\\\r\n()"']|\\[\s\S])*/.source + ')\\)', 'i'),
  1242. greedy: true,
  1243. inside: {
  1244. 'function': /^url/i,
  1245. 'punctuation': /^\(|\)$/,
  1246. 'string': {
  1247. pattern: RegExp('^' + string.source + '$'),
  1248. alias: 'url'
  1249. }
  1250. }
  1251. },
  1252. 'selector': {
  1253. pattern: RegExp('(^|[{}\\s])[^{}\\s](?:[^{};"\'\\s]|\\s+(?![\\s{])|' + string.source + ')*(?=\\s*\\{)'),
  1254. lookbehind: true
  1255. },
  1256. 'string': {
  1257. pattern: string,
  1258. greedy: true
  1259. },
  1260. 'property': {
  1261. pattern: /(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,
  1262. lookbehind: true
  1263. },
  1264. 'important': /!important\b/i,
  1265. 'function': {
  1266. pattern: /(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,
  1267. lookbehind: true
  1268. },
  1269. 'punctuation': /[(){};:,]/
  1270. };
  1271. Prism.languages.css['atrule'].inside.rest = Prism.languages.css;
  1272. var markup = Prism.languages.markup;
  1273. if (markup) {
  1274. markup.tag.addInlined('style', 'css');
  1275. markup.tag.addAttribute('style', 'css');
  1276. }
  1277. }(Prism));
  1278. (function (Prism) {
  1279. var keywords = /\b(?:abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|exports|extends|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|module|native|new|non-sealed|null|open|opens|package|permits|private|protected|provides|public|record(?!\s*[(){}[\]<>=%~.:,;?+\-*/&|^])|requires|return|sealed|short|static|strictfp|super|switch|synchronized|this|throw|throws|to|transient|transitive|try|uses|var|void|volatile|while|with|yield)\b/;
  1280. var classNamePrefix = /(?:[a-z]\w*\s*\.\s*)*(?:[A-Z]\w*\s*\.\s*)*/.source;
  1281. var className = {
  1282. pattern: RegExp(/(^|[^\w.])/.source + classNamePrefix + /[A-Z](?:[\d_A-Z]*[a-z]\w*)?\b/.source),
  1283. lookbehind: true,
  1284. inside: {
  1285. 'namespace': {
  1286. pattern: /^[a-z]\w*(?:\s*\.\s*[a-z]\w*)*(?:\s*\.)?/,
  1287. inside: { 'punctuation': /\./ }
  1288. },
  1289. 'punctuation': /\./
  1290. }
  1291. };
  1292. Prism.languages.java = Prism.languages.extend('clike', {
  1293. 'string': {
  1294. pattern: /(^|[^\\])"(?:\\.|[^"\\\r\n])*"/,
  1295. lookbehind: true,
  1296. greedy: true
  1297. },
  1298. 'class-name': [
  1299. className,
  1300. {
  1301. pattern: RegExp(/(^|[^\w.])/.source + classNamePrefix + /[A-Z]\w*(?=\s+\w+\s*[;,=()]|\s*(?:\[[\s,]*\]\s*)?::\s*new\b)/.source),
  1302. lookbehind: true,
  1303. inside: className.inside
  1304. },
  1305. {
  1306. pattern: RegExp(/(\b(?:class|enum|extends|implements|instanceof|interface|new|record|throws)\s+)/.source + classNamePrefix + /[A-Z]\w*\b/.source),
  1307. lookbehind: true,
  1308. inside: className.inside
  1309. }
  1310. ],
  1311. 'keyword': keywords,
  1312. 'function': [
  1313. Prism.languages.clike.function,
  1314. {
  1315. pattern: /(::\s*)[a-z_]\w*/,
  1316. lookbehind: true
  1317. }
  1318. ],
  1319. 'number': /\b0b[01][01_]*L?\b|\b0x(?:\.[\da-f_p+-]+|[\da-f_]+(?:\.[\da-f_p+-]+)?)\b|(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?\d[\d_]*)?[dfl]?/i,
  1320. 'operator': {
  1321. pattern: /(^|[^.])(?:<<=?|>>>?=?|->|--|\+\+|&&|\|\||::|[?:~]|[-+*/%&|^!=<>]=?)/m,
  1322. lookbehind: true
  1323. },
  1324. 'constant': /\b[A-Z][A-Z_\d]+\b/
  1325. });
  1326. Prism.languages.insertBefore('java', 'string', {
  1327. 'triple-quoted-string': {
  1328. pattern: /"""[ \t]*[\r\n](?:(?:"|"")?(?:\\.|[^"\\]))*"""/,
  1329. greedy: true,
  1330. alias: 'string'
  1331. },
  1332. 'char': {
  1333. pattern: /'(?:\\.|[^'\\\r\n]){1,6}'/,
  1334. greedy: true
  1335. }
  1336. });
  1337. Prism.languages.insertBefore('java', 'class-name', {
  1338. 'annotation': {
  1339. pattern: /(^|[^.])@\w+(?:\s*\.\s*\w+)*/,
  1340. lookbehind: true,
  1341. alias: 'punctuation'
  1342. },
  1343. 'generics': {
  1344. pattern: /<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&))*>)*>)*>)*>/,
  1345. inside: {
  1346. 'class-name': className,
  1347. 'keyword': keywords,
  1348. 'punctuation': /[<>(),.:]/,
  1349. 'operator': /[?&|]/
  1350. }
  1351. },
  1352. 'import': [
  1353. {
  1354. pattern: RegExp(/(\bimport\s+)/.source + classNamePrefix + /(?:[A-Z]\w*|\*)(?=\s*;)/.source),
  1355. lookbehind: true,
  1356. inside: {
  1357. 'namespace': className.inside.namespace,
  1358. 'punctuation': /\./,
  1359. 'operator': /\*/,
  1360. 'class-name': /\w+/
  1361. }
  1362. },
  1363. {
  1364. pattern: RegExp(/(\bimport\s+static\s+)/.source + classNamePrefix + /(?:\w+|\*)(?=\s*;)/.source),
  1365. lookbehind: true,
  1366. alias: 'static',
  1367. inside: {
  1368. 'namespace': className.inside.namespace,
  1369. 'static': /\b\w+$/,
  1370. 'punctuation': /\./,
  1371. 'operator': /\*/,
  1372. 'class-name': /\w+/
  1373. }
  1374. }
  1375. ],
  1376. 'namespace': {
  1377. pattern: RegExp(/(\b(?:exports|import(?:\s+static)?|module|open|opens|package|provides|requires|to|transitive|uses|with)\s+)(?!<keyword>)[a-z]\w*(?:\.[a-z]\w*)*\.?/.source.replace(/<keyword>/g, function () {
  1378. return keywords.source;
  1379. })),
  1380. lookbehind: true,
  1381. inside: { 'punctuation': /\./ }
  1382. }
  1383. });
  1384. }(Prism));
  1385. Prism.languages.javascript = Prism.languages.extend('clike', {
  1386. 'class-name': [
  1387. Prism.languages.clike['class-name'],
  1388. {
  1389. pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,
  1390. lookbehind: true
  1391. }
  1392. ],
  1393. 'keyword': [
  1394. {
  1395. pattern: /((?:^|\})\s*)catch\b/,
  1396. lookbehind: true
  1397. },
  1398. {
  1399. pattern: /(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,
  1400. lookbehind: true
  1401. }
  1402. ],
  1403. 'function': /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
  1404. 'number': {
  1405. pattern: RegExp(/(^|[^\w$])/.source + '(?:' + (/NaN|Infinity/.source + '|' + /0[bB][01]+(?:_[01]+)*n?/.source + '|' + /0[oO][0-7]+(?:_[0-7]+)*n?/.source + '|' + /0[xX][\dA-Fa-f]+(?:_[\dA-Fa-f]+)*n?/.source + '|' + /\d+(?:_\d+)*n/.source + '|' + /(?:\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[Ee][+-]?\d+(?:_\d+)*)?/.source) + ')' + /(?![\w$])/.source),
  1406. lookbehind: true
  1407. },
  1408. 'operator': /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/
  1409. });
  1410. Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/;
  1411. Prism.languages.insertBefore('javascript', 'keyword', {
  1412. 'regex': {
  1413. pattern: RegExp(/((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)/.source + /\//.source + '(?:' + /(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}/.source + '|' + /(?:\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.)*\])*\])*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}v[dgimyus]{0,7}/.source + ')' + /(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/.source),
  1414. lookbehind: true,
  1415. greedy: true,
  1416. inside: {
  1417. 'regex-source': {
  1418. pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/,
  1419. lookbehind: true,
  1420. alias: 'language-regex',
  1421. inside: Prism.languages.regex
  1422. },
  1423. 'regex-delimiter': /^\/|\/$/,
  1424. 'regex-flags': /^[a-z]+$/
  1425. }
  1426. },
  1427. 'function-variable': {
  1428. pattern: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,
  1429. alias: 'function'
  1430. },
  1431. 'parameter': [
  1432. {
  1433. pattern: /(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,
  1434. lookbehind: true,
  1435. inside: Prism.languages.javascript
  1436. },
  1437. {
  1438. pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,
  1439. lookbehind: true,
  1440. inside: Prism.languages.javascript
  1441. },
  1442. {
  1443. pattern: /(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,
  1444. lookbehind: true,
  1445. inside: Prism.languages.javascript
  1446. },
  1447. {
  1448. pattern: /((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/,
  1449. lookbehind: true,
  1450. inside: Prism.languages.javascript
  1451. }
  1452. ],
  1453. 'constant': /\b[A-Z](?:[A-Z_]|\dx?)*\b/
  1454. });
  1455. Prism.languages.insertBefore('javascript', 'string', {
  1456. 'hashbang': {
  1457. pattern: /^#!.*/,
  1458. greedy: true,
  1459. alias: 'comment'
  1460. },
  1461. 'template-string': {
  1462. pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
  1463. greedy: true,
  1464. inside: {
  1465. 'template-punctuation': {
  1466. pattern: /^`|`$/,
  1467. alias: 'string'
  1468. },
  1469. 'interpolation': {
  1470. pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
  1471. lookbehind: true,
  1472. inside: {
  1473. 'interpolation-punctuation': {
  1474. pattern: /^\$\{|\}$/,
  1475. alias: 'punctuation'
  1476. },
  1477. rest: Prism.languages.javascript
  1478. }
  1479. },
  1480. 'string': /[\s\S]+/
  1481. }
  1482. },
  1483. 'string-property': {
  1484. pattern: /((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,
  1485. lookbehind: true,
  1486. greedy: true,
  1487. alias: 'property'
  1488. }
  1489. });
  1490. Prism.languages.insertBefore('javascript', 'operator', {
  1491. 'literal-property': {
  1492. pattern: /((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,
  1493. lookbehind: true,
  1494. alias: 'property'
  1495. }
  1496. });
  1497. if (Prism.languages.markup) {
  1498. Prism.languages.markup.tag.addInlined('script', 'javascript');
  1499. Prism.languages.markup.tag.addAttribute(/on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)/.source, 'javascript');
  1500. }
  1501. Prism.languages.js = Prism.languages.javascript;
  1502. Prism.languages.markup = {
  1503. 'comment': {
  1504. pattern: /<!--(?:(?!<!--)[\s\S])*?-->/,
  1505. greedy: true
  1506. },
  1507. 'prolog': {
  1508. pattern: /<\?[\s\S]+?\?>/,
  1509. greedy: true
  1510. },
  1511. 'doctype': {
  1512. pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,
  1513. greedy: true,
  1514. inside: {
  1515. 'internal-subset': {
  1516. pattern: /(^[^\[]*\[)[\s\S]+(?=\]>$)/,
  1517. lookbehind: true,
  1518. greedy: true,
  1519. inside: null
  1520. },
  1521. 'string': {
  1522. pattern: /"[^"]*"|'[^']*'/,
  1523. greedy: true
  1524. },
  1525. 'punctuation': /^<!|>$|[[\]]/,
  1526. 'doctype-tag': /^DOCTYPE/i,
  1527. 'name': /[^\s<>'"]+/
  1528. }
  1529. },
  1530. 'cdata': {
  1531. pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
  1532. greedy: true
  1533. },
  1534. 'tag': {
  1535. pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,
  1536. greedy: true,
  1537. inside: {
  1538. 'tag': {
  1539. pattern: /^<\/?[^\s>\/]+/,
  1540. inside: {
  1541. 'punctuation': /^<\/?/,
  1542. 'namespace': /^[^\s>\/:]+:/
  1543. }
  1544. },
  1545. 'special-attr': [],
  1546. 'attr-value': {
  1547. pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,
  1548. inside: {
  1549. 'punctuation': [
  1550. {
  1551. pattern: /^=/,
  1552. alias: 'attr-equals'
  1553. },
  1554. {
  1555. pattern: /^(\s*)["']|["']$/,
  1556. lookbehind: true
  1557. }
  1558. ]
  1559. }
  1560. },
  1561. 'punctuation': /\/?>/,
  1562. 'attr-name': {
  1563. pattern: /[^\s>\/]+/,
  1564. inside: { 'namespace': /^[^\s>\/:]+:/ }
  1565. }
  1566. }
  1567. },
  1568. 'entity': [
  1569. {
  1570. pattern: /&[\da-z]{1,8};/i,
  1571. alias: 'named-entity'
  1572. },
  1573. /&#x?[\da-f]{1,8};/i
  1574. ]
  1575. };
  1576. Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] = Prism.languages.markup['entity'];
  1577. Prism.languages.markup['doctype'].inside['internal-subset'].inside = Prism.languages.markup;
  1578. Prism.hooks.add('wrap', function (env) {
  1579. if (env.type === 'entity') {
  1580. env.attributes['title'] = env.content.replace(/&amp;/, '&');
  1581. }
  1582. });
  1583. Object.defineProperty(Prism.languages.markup.tag, 'addInlined', {
  1584. value: function addInlined(tagName, lang) {
  1585. var includedCdataInside = {};
  1586. includedCdataInside['language-' + lang] = {
  1587. pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
  1588. lookbehind: true,
  1589. inside: Prism.languages[lang]
  1590. };
  1591. includedCdataInside['cdata'] = /^<!\[CDATA\[|\]\]>$/i;
  1592. var inside = {
  1593. 'included-cdata': {
  1594. pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
  1595. inside: includedCdataInside
  1596. }
  1597. };
  1598. inside['language-' + lang] = {
  1599. pattern: /[\s\S]+/,
  1600. inside: Prism.languages[lang]
  1601. };
  1602. var def = {};
  1603. def[tagName] = {
  1604. pattern: RegExp(/(<__[^>]*>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(/__/g, function () {
  1605. return tagName;
  1606. }), 'i'),
  1607. lookbehind: true,
  1608. greedy: true,
  1609. inside: inside
  1610. };
  1611. Prism.languages.insertBefore('markup', 'cdata', def);
  1612. }
  1613. });
  1614. Object.defineProperty(Prism.languages.markup.tag, 'addAttribute', {
  1615. value: function (attrName, lang) {
  1616. Prism.languages.markup.tag.inside['special-attr'].push({
  1617. pattern: RegExp(/(^|["'\s])/.source + '(?:' + attrName + ')' + /\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source, 'i'),
  1618. lookbehind: true,
  1619. inside: {
  1620. 'attr-name': /^[^\s=]+/,
  1621. 'attr-value': {
  1622. pattern: /=[\s\S]+/,
  1623. inside: {
  1624. 'value': {
  1625. pattern: /(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,
  1626. lookbehind: true,
  1627. alias: [
  1628. lang,
  1629. 'language-' + lang
  1630. ],
  1631. inside: Prism.languages[lang]
  1632. },
  1633. 'punctuation': [
  1634. {
  1635. pattern: /^=/,
  1636. alias: 'attr-equals'
  1637. },
  1638. /"|'/
  1639. ]
  1640. }
  1641. }
  1642. }
  1643. });
  1644. }
  1645. });
  1646. Prism.languages.html = Prism.languages.markup;
  1647. Prism.languages.mathml = Prism.languages.markup;
  1648. Prism.languages.svg = Prism.languages.markup;
  1649. Prism.languages.xml = Prism.languages.extend('markup', {});
  1650. Prism.languages.ssml = Prism.languages.xml;
  1651. Prism.languages.atom = Prism.languages.xml;
  1652. Prism.languages.rss = Prism.languages.xml;
  1653. (function (Prism) {
  1654. var comment = /\/\*[\s\S]*?\*\/|\/\/.*|#(?!\[).*/;
  1655. var constant = [
  1656. {
  1657. pattern: /\b(?:false|true)\b/i,
  1658. alias: 'boolean'
  1659. },
  1660. {
  1661. pattern: /(::\s*)\b[a-z_]\w*\b(?!\s*\()/i,
  1662. greedy: true,
  1663. lookbehind: true
  1664. },
  1665. {
  1666. pattern: /(\b(?:case|const)\s+)\b[a-z_]\w*(?=\s*[;=])/i,
  1667. greedy: true,
  1668. lookbehind: true
  1669. },
  1670. /\b(?:null)\b/i,
  1671. /\b[A-Z_][A-Z0-9_]*\b(?!\s*\()/
  1672. ];
  1673. var number = /\b0b[01]+(?:_[01]+)*\b|\b0o[0-7]+(?:_[0-7]+)*\b|\b0x[\da-f]+(?:_[\da-f]+)*\b|(?:\b\d+(?:_\d+)*\.?(?:\d+(?:_\d+)*)?|\B\.\d+)(?:e[+-]?\d+)?/i;
  1674. var operator = /<?=>|\?\?=?|\.{3}|\??->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||<<|>>|[?~]|[/^|%*&<>.+-]=?/;
  1675. var punctuation = /[{}\[\](),:;]/;
  1676. Prism.languages.php = {
  1677. 'delimiter': {
  1678. pattern: /\?>$|^<\?(?:php(?=\s)|=)?/i,
  1679. alias: 'important'
  1680. },
  1681. 'comment': comment,
  1682. 'variable': /\$+(?:\w+\b|(?=\{))/,
  1683. 'package': {
  1684. pattern: /(namespace\s+|use\s+(?:function\s+)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,
  1685. lookbehind: true,
  1686. inside: { 'punctuation': /\\/ }
  1687. },
  1688. 'class-name-definition': {
  1689. pattern: /(\b(?:class|enum|interface|trait)\s+)\b[a-z_]\w*(?!\\)\b/i,
  1690. lookbehind: true,
  1691. alias: 'class-name'
  1692. },
  1693. 'function-definition': {
  1694. pattern: /(\bfunction\s+)[a-z_]\w*(?=\s*\()/i,
  1695. lookbehind: true,
  1696. alias: 'function'
  1697. },
  1698. 'keyword': [
  1699. {
  1700. pattern: /(\(\s*)\b(?:array|bool|boolean|float|int|integer|object|string)\b(?=\s*\))/i,
  1701. alias: 'type-casting',
  1702. greedy: true,
  1703. lookbehind: true
  1704. },
  1705. {
  1706. pattern: /([(,?]\s*)\b(?:array(?!\s*\()|bool|callable|(?:false|null)(?=\s*\|)|float|int|iterable|mixed|object|self|static|string)\b(?=\s*\$)/i,
  1707. alias: 'type-hint',
  1708. greedy: true,
  1709. lookbehind: true
  1710. },
  1711. {
  1712. pattern: /(\)\s*:\s*(?:\?\s*)?)\b(?:array(?!\s*\()|bool|callable|(?:false|null)(?=\s*\|)|float|int|iterable|mixed|never|object|self|static|string|void)\b/i,
  1713. alias: 'return-type',
  1714. greedy: true,
  1715. lookbehind: true
  1716. },
  1717. {
  1718. pattern: /\b(?:array(?!\s*\()|bool|float|int|iterable|mixed|object|string|void)\b/i,
  1719. alias: 'type-declaration',
  1720. greedy: true
  1721. },
  1722. {
  1723. pattern: /(\|\s*)(?:false|null)\b|\b(?:false|null)(?=\s*\|)/i,
  1724. alias: 'type-declaration',
  1725. greedy: true,
  1726. lookbehind: true
  1727. },
  1728. {
  1729. pattern: /\b(?:parent|self|static)(?=\s*::)/i,
  1730. alias: 'static-context',
  1731. greedy: true
  1732. },
  1733. {
  1734. pattern: /(\byield\s+)from\b/i,
  1735. lookbehind: true
  1736. },
  1737. /\bclass\b/i,
  1738. {
  1739. pattern: /((?:^|[^\s>:]|(?:^|[^-])>|(?:^|[^:]):)\s*)\b(?:abstract|and|array|as|break|callable|case|catch|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|enum|eval|exit|extends|final|finally|fn|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|match|namespace|never|new|or|parent|print|private|protected|public|readonly|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield|__halt_compiler)\b/i,
  1740. lookbehind: true
  1741. }
  1742. ],
  1743. 'argument-name': {
  1744. pattern: /([(,]\s*)\b[a-z_]\w*(?=\s*:(?!:))/i,
  1745. lookbehind: true
  1746. },
  1747. 'class-name': [
  1748. {
  1749. pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s*\()\b[a-z_]\w*(?!\\)\b/i,
  1750. greedy: true,
  1751. lookbehind: true
  1752. },
  1753. {
  1754. pattern: /(\|\s*)\b[a-z_]\w*(?!\\)\b/i,
  1755. greedy: true,
  1756. lookbehind: true
  1757. },
  1758. {
  1759. pattern: /\b[a-z_]\w*(?!\\)\b(?=\s*\|)/i,
  1760. greedy: true
  1761. },
  1762. {
  1763. pattern: /(\|\s*)(?:\\?\b[a-z_]\w*)+\b/i,
  1764. alias: 'class-name-fully-qualified',
  1765. greedy: true,
  1766. lookbehind: true,
  1767. inside: { 'punctuation': /\\/ }
  1768. },
  1769. {
  1770. pattern: /(?:\\?\b[a-z_]\w*)+\b(?=\s*\|)/i,
  1771. alias: 'class-name-fully-qualified',
  1772. greedy: true,
  1773. inside: { 'punctuation': /\\/ }
  1774. },
  1775. {
  1776. pattern: /(\b(?:extends|implements|instanceof|new(?!\s+self\b|\s+static\b))\s+|\bcatch\s*\()(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,
  1777. alias: 'class-name-fully-qualified',
  1778. greedy: true,
  1779. lookbehind: true,
  1780. inside: { 'punctuation': /\\/ }
  1781. },
  1782. {
  1783. pattern: /\b[a-z_]\w*(?=\s*\$)/i,
  1784. alias: 'type-declaration',
  1785. greedy: true
  1786. },
  1787. {
  1788. pattern: /(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,
  1789. alias: [
  1790. 'class-name-fully-qualified',
  1791. 'type-declaration'
  1792. ],
  1793. greedy: true,
  1794. inside: { 'punctuation': /\\/ }
  1795. },
  1796. {
  1797. pattern: /\b[a-z_]\w*(?=\s*::)/i,
  1798. alias: 'static-context',
  1799. greedy: true
  1800. },
  1801. {
  1802. pattern: /(?:\\?\b[a-z_]\w*)+(?=\s*::)/i,
  1803. alias: [
  1804. 'class-name-fully-qualified',
  1805. 'static-context'
  1806. ],
  1807. greedy: true,
  1808. inside: { 'punctuation': /\\/ }
  1809. },
  1810. {
  1811. pattern: /([(,?]\s*)[a-z_]\w*(?=\s*\$)/i,
  1812. alias: 'type-hint',
  1813. greedy: true,
  1814. lookbehind: true
  1815. },
  1816. {
  1817. pattern: /([(,?]\s*)(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,
  1818. alias: [
  1819. 'class-name-fully-qualified',
  1820. 'type-hint'
  1821. ],
  1822. greedy: true,
  1823. lookbehind: true,
  1824. inside: { 'punctuation': /\\/ }
  1825. },
  1826. {
  1827. pattern: /(\)\s*:\s*(?:\?\s*)?)\b[a-z_]\w*(?!\\)\b/i,
  1828. alias: 'return-type',
  1829. greedy: true,
  1830. lookbehind: true
  1831. },
  1832. {
  1833. pattern: /(\)\s*:\s*(?:\?\s*)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,
  1834. alias: [
  1835. 'class-name-fully-qualified',
  1836. 'return-type'
  1837. ],
  1838. greedy: true,
  1839. lookbehind: true,
  1840. inside: { 'punctuation': /\\/ }
  1841. }
  1842. ],
  1843. 'constant': constant,
  1844. 'function': {
  1845. pattern: /(^|[^\\\w])\\?[a-z_](?:[\w\\]*\w)?(?=\s*\()/i,
  1846. lookbehind: true,
  1847. inside: { 'punctuation': /\\/ }
  1848. },
  1849. 'property': {
  1850. pattern: /(->\s*)\w+/,
  1851. lookbehind: true
  1852. },
  1853. 'number': number,
  1854. 'operator': operator,
  1855. 'punctuation': punctuation
  1856. };
  1857. var string_interpolation = {
  1858. pattern: /\{\$(?:\{(?:\{[^{}]+\}|[^{}]+)\}|[^{}])+\}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)?)/,
  1859. lookbehind: true,
  1860. inside: Prism.languages.php
  1861. };
  1862. var string = [
  1863. {
  1864. pattern: /<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,
  1865. alias: 'nowdoc-string',
  1866. greedy: true,
  1867. inside: {
  1868. 'delimiter': {
  1869. pattern: /^<<<'[^']+'|[a-z_]\w*;$/i,
  1870. alias: 'symbol',
  1871. inside: { 'punctuation': /^<<<'?|[';]$/ }
  1872. }
  1873. }
  1874. },
  1875. {
  1876. pattern: /<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,
  1877. alias: 'heredoc-string',
  1878. greedy: true,
  1879. inside: {
  1880. 'delimiter': {
  1881. pattern: /^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,
  1882. alias: 'symbol',
  1883. inside: { 'punctuation': /^<<<"?|[";]$/ }
  1884. },
  1885. 'interpolation': string_interpolation
  1886. }
  1887. },
  1888. {
  1889. pattern: /`(?:\\[\s\S]|[^\\`])*`/,
  1890. alias: 'backtick-quoted-string',
  1891. greedy: true
  1892. },
  1893. {
  1894. pattern: /'(?:\\[\s\S]|[^\\'])*'/,
  1895. alias: 'single-quoted-string',
  1896. greedy: true
  1897. },
  1898. {
  1899. pattern: /"(?:\\[\s\S]|[^\\"])*"/,
  1900. alias: 'double-quoted-string',
  1901. greedy: true,
  1902. inside: { 'interpolation': string_interpolation }
  1903. }
  1904. ];
  1905. Prism.languages.insertBefore('php', 'variable', {
  1906. 'string': string,
  1907. 'attribute': {
  1908. pattern: /#\[(?:[^"'\/#]|\/(?![*/])|\/\/.*$|#(?!\[).*$|\/\*(?:[^*]|\*(?!\/))*\*\/|"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*')+\](?=\s*[a-z$#])/im,
  1909. greedy: true,
  1910. inside: {
  1911. 'attribute-content': {
  1912. pattern: /^(#\[)[\s\S]+(?=\]$)/,
  1913. lookbehind: true,
  1914. inside: {
  1915. 'comment': comment,
  1916. 'string': string,
  1917. 'attribute-class-name': [
  1918. {
  1919. pattern: /([^:]|^)\b[a-z_]\w*(?!\\)\b/i,
  1920. alias: 'class-name',
  1921. greedy: true,
  1922. lookbehind: true
  1923. },
  1924. {
  1925. pattern: /([^:]|^)(?:\\?\b[a-z_]\w*)+/i,
  1926. alias: [
  1927. 'class-name',
  1928. 'class-name-fully-qualified'
  1929. ],
  1930. greedy: true,
  1931. lookbehind: true,
  1932. inside: { 'punctuation': /\\/ }
  1933. }
  1934. ],
  1935. 'constant': constant,
  1936. 'number': number,
  1937. 'operator': operator,
  1938. 'punctuation': punctuation
  1939. }
  1940. },
  1941. 'delimiter': {
  1942. pattern: /^#\[|\]$/,
  1943. alias: 'punctuation'
  1944. }
  1945. }
  1946. }
  1947. });
  1948. Prism.hooks.add('before-tokenize', function (env) {
  1949. if (!/<\?/.test(env.code)) {
  1950. return;
  1951. }
  1952. var phpPattern = /<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#(?!\[))(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|#\[|\/\*(?:[^*]|\*(?!\/))*(?:\*\/|$))*?(?:\?>|$)/g;
  1953. Prism.languages['markup-templating'].buildPlaceholders(env, 'php', phpPattern);
  1954. });
  1955. Prism.hooks.add('after-tokenize', function (env) {
  1956. Prism.languages['markup-templating'].tokenizePlaceholders(env, 'php');
  1957. });
  1958. }(Prism));
  1959. Prism.languages.python = {
  1960. 'comment': {
  1961. pattern: /(^|[^\\])#.*/,
  1962. lookbehind: true,
  1963. greedy: true
  1964. },
  1965. 'string-interpolation': {
  1966. pattern: /(?:f|fr|rf)(?:("""|''')[\s\S]*?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i,
  1967. greedy: true,
  1968. inside: {
  1969. 'interpolation': {
  1970. pattern: /((?:^|[^{])(?:\{\{)*)\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}])+\})+\})+\}/,
  1971. lookbehind: true,
  1972. inside: {
  1973. 'format-spec': {
  1974. pattern: /(:)[^:(){}]+(?=\}$)/,
  1975. lookbehind: true
  1976. },
  1977. 'conversion-option': {
  1978. pattern: /![sra](?=[:}]$)/,
  1979. alias: 'punctuation'
  1980. },
  1981. rest: null
  1982. }
  1983. },
  1984. 'string': /[\s\S]+/
  1985. }
  1986. },
  1987. 'triple-quoted-string': {
  1988. pattern: /(?:[rub]|br|rb)?("""|''')[\s\S]*?\1/i,
  1989. greedy: true,
  1990. alias: 'string'
  1991. },
  1992. 'string': {
  1993. pattern: /(?:[rub]|br|rb)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i,
  1994. greedy: true
  1995. },
  1996. 'function': {
  1997. pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,
  1998. lookbehind: true
  1999. },
  2000. 'class-name': {
  2001. pattern: /(\bclass\s+)\w+/i,
  2002. lookbehind: true
  2003. },
  2004. 'decorator': {
  2005. pattern: /(^[\t ]*)@\w+(?:\.\w+)*/m,
  2006. lookbehind: true,
  2007. alias: [
  2008. 'annotation',
  2009. 'punctuation'
  2010. ],
  2011. inside: { 'punctuation': /\./ }
  2012. },
  2013. 'keyword': /\b(?:_(?=\s*:)|and|as|assert|async|await|break|case|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|match|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b/,
  2014. 'builtin': /\b(?:__import__|abs|all|any|apply|ascii|basestring|bin|bool|buffer|bytearray|bytes|callable|chr|classmethod|cmp|coerce|compile|complex|delattr|dict|dir|divmod|enumerate|eval|execfile|file|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|intern|isinstance|issubclass|iter|len|list|locals|long|map|max|memoryview|min|next|object|oct|open|ord|pow|property|range|raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|unichr|unicode|vars|xrange|zip)\b/,
  2015. 'boolean': /\b(?:False|None|True)\b/,
  2016. 'number': /\b0(?:b(?:_?[01])+|o(?:_?[0-7])+|x(?:_?[a-f0-9])+)\b|(?:\b\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\B\.\d+(?:_\d+)*)(?:e[+-]?\d+(?:_\d+)*)?j?(?!\w)/i,
  2017. 'operator': /[-+%=]=?|!=|:=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,
  2018. 'punctuation': /[{}[\];(),.:]/
  2019. };
  2020. Prism.languages.python['string-interpolation'].inside['interpolation'].inside.rest = Prism.languages.python;
  2021. Prism.languages.py = Prism.languages.python;
  2022. (function (Prism) {
  2023. Prism.languages.ruby = Prism.languages.extend('clike', {
  2024. 'comment': {
  2025. pattern: /#.*|^=begin\s[\s\S]*?^=end/m,
  2026. greedy: true
  2027. },
  2028. 'class-name': {
  2029. pattern: /(\b(?:class|module)\s+|\bcatch\s+\()[\w.\\]+|\b[A-Z_]\w*(?=\s*\.\s*new\b)/,
  2030. lookbehind: true,
  2031. inside: { 'punctuation': /[.\\]/ }
  2032. },
  2033. 'keyword': /\b(?:BEGIN|END|alias|and|begin|break|case|class|def|define_method|defined|do|each|else|elsif|end|ensure|extend|for|if|in|include|module|new|next|nil|not|or|prepend|private|protected|public|raise|redo|require|rescue|retry|return|self|super|then|throw|undef|unless|until|when|while|yield)\b/,
  2034. 'operator': /\.{2,3}|&\.|===|<?=>|[!=]?~|(?:&&|\|\||<<|>>|\*\*|[+\-*/%<>!^&|=])=?|[?:]/,
  2035. 'punctuation': /[(){}[\].,;]/
  2036. });
  2037. Prism.languages.insertBefore('ruby', 'operator', {
  2038. 'double-colon': {
  2039. pattern: /::/,
  2040. alias: 'punctuation'
  2041. }
  2042. });
  2043. var interpolation = {
  2044. pattern: /((?:^|[^\\])(?:\\{2})*)#\{(?:[^{}]|\{[^{}]*\})*\}/,
  2045. lookbehind: true,
  2046. inside: {
  2047. 'content': {
  2048. pattern: /^(#\{)[\s\S]+(?=\}$)/,
  2049. lookbehind: true,
  2050. inside: Prism.languages.ruby
  2051. },
  2052. 'delimiter': {
  2053. pattern: /^#\{|\}$/,
  2054. alias: 'punctuation'
  2055. }
  2056. }
  2057. };
  2058. delete Prism.languages.ruby.function;
  2059. var percentExpression = '(?:' + [
  2060. /([^a-zA-Z0-9\s{(\[<=])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source,
  2061. /\((?:[^()\\]|\\[\s\S]|\((?:[^()\\]|\\[\s\S])*\))*\)/.source,
  2062. /\{(?:[^{}\\]|\\[\s\S]|\{(?:[^{}\\]|\\[\s\S])*\})*\}/.source,
  2063. /\[(?:[^\[\]\\]|\\[\s\S]|\[(?:[^\[\]\\]|\\[\s\S])*\])*\]/.source,
  2064. /<(?:[^<>\\]|\\[\s\S]|<(?:[^<>\\]|\\[\s\S])*>)*>/.source
  2065. ].join('|') + ')';
  2066. var symbolName = /(?:"(?:\\.|[^"\\\r\n])*"|(?:\b[a-zA-Z_]\w*|[^\s\0-\x7F]+)[?!]?|\$.)/.source;
  2067. Prism.languages.insertBefore('ruby', 'keyword', {
  2068. 'regex-literal': [
  2069. {
  2070. pattern: RegExp(/%r/.source + percentExpression + /[egimnosux]{0,6}/.source),
  2071. greedy: true,
  2072. inside: {
  2073. 'interpolation': interpolation,
  2074. 'regex': /[\s\S]+/
  2075. }
  2076. },
  2077. {
  2078. pattern: /(^|[^/])\/(?!\/)(?:\[[^\r\n\]]+\]|\\.|[^[/\\\r\n])+\/[egimnosux]{0,6}(?=\s*(?:$|[\r\n,.;})#]))/,
  2079. lookbehind: true,
  2080. greedy: true,
  2081. inside: {
  2082. 'interpolation': interpolation,
  2083. 'regex': /[\s\S]+/
  2084. }
  2085. }
  2086. ],
  2087. 'variable': /[@$]+[a-zA-Z_]\w*(?:[?!]|\b)/,
  2088. 'symbol': [
  2089. {
  2090. pattern: RegExp(/(^|[^:]):/.source + symbolName),
  2091. lookbehind: true,
  2092. greedy: true
  2093. },
  2094. {
  2095. pattern: RegExp(/([\r\n{(,][ \t]*)/.source + symbolName + /(?=:(?!:))/.source),
  2096. lookbehind: true,
  2097. greedy: true
  2098. }
  2099. ],
  2100. 'method-definition': {
  2101. pattern: /(\bdef\s+)\w+(?:\s*\.\s*\w+)?/,
  2102. lookbehind: true,
  2103. inside: {
  2104. 'function': /\b\w+$/,
  2105. 'keyword': /^self\b/,
  2106. 'class-name': /^\w+/,
  2107. 'punctuation': /\./
  2108. }
  2109. }
  2110. });
  2111. Prism.languages.insertBefore('ruby', 'string', {
  2112. 'string-literal': [
  2113. {
  2114. pattern: RegExp(/%[qQiIwWs]?/.source + percentExpression),
  2115. greedy: true,
  2116. inside: {
  2117. 'interpolation': interpolation,
  2118. 'string': /[\s\S]+/
  2119. }
  2120. },
  2121. {
  2122. pattern: /("|')(?:#\{[^}]+\}|#(?!\{)|\\(?:\r\n|[\s\S])|(?!\1)[^\\#\r\n])*\1/,
  2123. greedy: true,
  2124. inside: {
  2125. 'interpolation': interpolation,
  2126. 'string': /[\s\S]+/
  2127. }
  2128. },
  2129. {
  2130. pattern: /<<[-~]?([a-z_]\w*)[\r\n](?:.*[\r\n])*?[\t ]*\1/i,
  2131. alias: 'heredoc-string',
  2132. greedy: true,
  2133. inside: {
  2134. 'delimiter': {
  2135. pattern: /^<<[-~]?[a-z_]\w*|\b[a-z_]\w*$/i,
  2136. inside: {
  2137. 'symbol': /\b\w+/,
  2138. 'punctuation': /^<<[-~]?/
  2139. }
  2140. },
  2141. 'interpolation': interpolation,
  2142. 'string': /[\s\S]+/
  2143. }
  2144. },
  2145. {
  2146. pattern: /<<[-~]?'([a-z_]\w*)'[\r\n](?:.*[\r\n])*?[\t ]*\1/i,
  2147. alias: 'heredoc-string',
  2148. greedy: true,
  2149. inside: {
  2150. 'delimiter': {
  2151. pattern: /^<<[-~]?'[a-z_]\w*'|\b[a-z_]\w*$/i,
  2152. inside: {
  2153. 'symbol': /\b\w+/,
  2154. 'punctuation': /^<<[-~]?'|'$/
  2155. }
  2156. },
  2157. 'string': /[\s\S]+/
  2158. }
  2159. }
  2160. ],
  2161. 'command-literal': [
  2162. {
  2163. pattern: RegExp(/%x/.source + percentExpression),
  2164. greedy: true,
  2165. inside: {
  2166. 'interpolation': interpolation,
  2167. 'command': {
  2168. pattern: /[\s\S]+/,
  2169. alias: 'string'
  2170. }
  2171. }
  2172. },
  2173. {
  2174. pattern: /`(?:#\{[^}]+\}|#(?!\{)|\\(?:\r\n|[\s\S])|[^\\`#\r\n])*`/,
  2175. greedy: true,
  2176. inside: {
  2177. 'interpolation': interpolation,
  2178. 'command': {
  2179. pattern: /[\s\S]+/,
  2180. alias: 'string'
  2181. }
  2182. }
  2183. }
  2184. ]
  2185. });
  2186. delete Prism.languages.ruby.string;
  2187. Prism.languages.insertBefore('ruby', 'number', {
  2188. 'builtin': /\b(?:Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Fixnum|Float|Hash|IO|Integer|MatchData|Method|Module|NilClass|Numeric|Object|Proc|Range|Regexp|Stat|String|Struct|Symbol|TMS|Thread|ThreadGroup|Time|TrueClass)\b/,
  2189. 'constant': /\b[A-Z][A-Z0-9_]*(?:[?!]|\b)/
  2190. });
  2191. Prism.languages.rb = Prism.languages.ruby;
  2192. }(Prism));
  2193. window.Prism = oldprism;
  2194. return Prism;
  2195. }(undefined, undefined);
  2196. const option = name => editor => editor.options.get(name);
  2197. const register$2 = editor => {
  2198. const registerOption = editor.options.register;
  2199. registerOption('codesample_languages', { processor: 'object[]' });
  2200. registerOption('codesample_global_prismjs', {
  2201. processor: 'boolean',
  2202. default: false
  2203. });
  2204. };
  2205. const getLanguages$1 = option('codesample_languages');
  2206. const useGlobalPrismJS = option('codesample_global_prismjs');
  2207. const get = editor => Global.Prism && useGlobalPrismJS(editor) ? Global.Prism : prismjs;
  2208. const isCodeSample = elm => {
  2209. return isNonNullable(elm) && elm.nodeName === 'PRE' && elm.className.indexOf('language-') !== -1;
  2210. };
  2211. const getSelectedCodeSample = editor => {
  2212. const node = editor.selection ? editor.selection.getNode() : null;
  2213. return isCodeSample(node) ? Optional.some(node) : Optional.none();
  2214. };
  2215. const insertCodeSample = (editor, language, code) => {
  2216. const dom = editor.dom;
  2217. editor.undoManager.transact(() => {
  2218. const node = getSelectedCodeSample(editor);
  2219. code = global$1.DOM.encode(code);
  2220. return node.fold(() => {
  2221. editor.insertContent('<pre id="__new" class="language-' + language + '">' + code + '</pre>');
  2222. const newPre = dom.select('#__new')[0];
  2223. dom.setAttrib(newPre, 'id', null);
  2224. editor.selection.select(newPre);
  2225. }, n => {
  2226. dom.setAttrib(n, 'class', 'language-' + language);
  2227. n.innerHTML = code;
  2228. get(editor).highlightElement(n);
  2229. editor.selection.select(n);
  2230. });
  2231. });
  2232. };
  2233. const getCurrentCode = editor => {
  2234. const node = getSelectedCodeSample(editor);
  2235. return node.bind(n => Optional.from(n.textContent)).getOr('');
  2236. };
  2237. const getLanguages = editor => {
  2238. const defaultLanguages = [
  2239. {
  2240. text: 'HTML/XML',
  2241. value: 'markup'
  2242. },
  2243. {
  2244. text: 'JavaScript',
  2245. value: 'javascript'
  2246. },
  2247. {
  2248. text: 'CSS',
  2249. value: 'css'
  2250. },
  2251. {
  2252. text: 'PHP',
  2253. value: 'php'
  2254. },
  2255. {
  2256. text: 'Ruby',
  2257. value: 'ruby'
  2258. },
  2259. {
  2260. text: 'Python',
  2261. value: 'python'
  2262. },
  2263. {
  2264. text: 'Java',
  2265. value: 'java'
  2266. },
  2267. {
  2268. text: 'C',
  2269. value: 'c'
  2270. },
  2271. {
  2272. text: 'C#',
  2273. value: 'csharp'
  2274. },
  2275. {
  2276. text: 'C++',
  2277. value: 'cpp'
  2278. }
  2279. ];
  2280. const customLanguages = getLanguages$1(editor);
  2281. return customLanguages ? customLanguages : defaultLanguages;
  2282. };
  2283. const getCurrentLanguage = (editor, fallback) => {
  2284. const node = getSelectedCodeSample(editor);
  2285. return node.fold(() => fallback, n => {
  2286. const matches = n.className.match(/language-(\w+)/);
  2287. return matches ? matches[1] : fallback;
  2288. });
  2289. };
  2290. const open = editor => {
  2291. const languages = getLanguages(editor);
  2292. const defaultLanguage = head(languages).fold(constant(''), l => l.value);
  2293. const currentLanguage = getCurrentLanguage(editor, defaultLanguage);
  2294. const currentCode = getCurrentCode(editor);
  2295. editor.windowManager.open({
  2296. title: 'Insert/Edit Code Sample',
  2297. size: 'large',
  2298. body: {
  2299. type: 'panel',
  2300. items: [
  2301. {
  2302. type: 'listbox',
  2303. name: 'language',
  2304. label: 'Language',
  2305. items: languages
  2306. },
  2307. {
  2308. type: 'textarea',
  2309. name: 'code',
  2310. label: 'Code view'
  2311. }
  2312. ]
  2313. },
  2314. buttons: [
  2315. {
  2316. type: 'cancel',
  2317. name: 'cancel',
  2318. text: 'Cancel'
  2319. },
  2320. {
  2321. type: 'submit',
  2322. name: 'save',
  2323. text: 'Save',
  2324. primary: true
  2325. }
  2326. ],
  2327. initialData: {
  2328. language: currentLanguage,
  2329. code: currentCode
  2330. },
  2331. onSubmit: api => {
  2332. const data = api.getData();
  2333. insertCodeSample(editor, data.language, data.code);
  2334. api.close();
  2335. }
  2336. });
  2337. };
  2338. const register$1 = editor => {
  2339. editor.addCommand('codesample', () => {
  2340. const node = editor.selection.getNode();
  2341. if (editor.selection.isCollapsed() || isCodeSample(node)) {
  2342. open(editor);
  2343. } else {
  2344. editor.formatter.toggle('code');
  2345. }
  2346. });
  2347. };
  2348. const blank = r => s => s.replace(r, '');
  2349. const trim = blank(/^\s+|\s+$/g);
  2350. var global = tinymce.util.Tools.resolve('tinymce.util.Tools');
  2351. const setup = editor => {
  2352. editor.on('PreProcess', e => {
  2353. const dom = editor.dom;
  2354. const pres = dom.select('pre[contenteditable=false]', e.node);
  2355. global.each(global.grep(pres, isCodeSample), elm => {
  2356. const code = elm.textContent;
  2357. dom.setAttrib(elm, 'class', trim(dom.getAttrib(elm, 'class')));
  2358. dom.setAttrib(elm, 'contentEditable', null);
  2359. dom.setAttrib(elm, 'data-mce-highlighted', null);
  2360. let child;
  2361. while (child = elm.firstChild) {
  2362. elm.removeChild(child);
  2363. }
  2364. const codeElm = dom.add(elm, 'code');
  2365. codeElm.textContent = code;
  2366. });
  2367. });
  2368. editor.on('SetContent', () => {
  2369. const dom = editor.dom;
  2370. const unprocessedCodeSamples = global.grep(dom.select('pre'), elm => {
  2371. return isCodeSample(elm) && dom.getAttrib(elm, 'data-mce-highlighted') !== 'true';
  2372. });
  2373. if (unprocessedCodeSamples.length) {
  2374. editor.undoManager.transact(() => {
  2375. global.each(unprocessedCodeSamples, elm => {
  2376. var _a;
  2377. global.each(dom.select('br', elm), elm => {
  2378. dom.replace(editor.getDoc().createTextNode('\n'), elm);
  2379. });
  2380. elm.innerHTML = dom.encode((_a = elm.textContent) !== null && _a !== void 0 ? _a : '');
  2381. get(editor).highlightElement(elm);
  2382. dom.setAttrib(elm, 'data-mce-highlighted', true);
  2383. elm.className = trim(elm.className);
  2384. });
  2385. });
  2386. }
  2387. });
  2388. editor.on('PreInit', () => {
  2389. editor.parser.addNodeFilter('pre', nodes => {
  2390. var _a;
  2391. for (let i = 0, l = nodes.length; i < l; i++) {
  2392. const node = nodes[i];
  2393. const isCodeSample = ((_a = node.attr('class')) !== null && _a !== void 0 ? _a : '').indexOf('language-') !== -1;
  2394. if (isCodeSample) {
  2395. node.attr('contenteditable', 'false');
  2396. node.attr('data-mce-highlighted', 'false');
  2397. }
  2398. }
  2399. });
  2400. });
  2401. };
  2402. const onSetupEditable = (editor, onChanged = noop) => api => {
  2403. const nodeChanged = () => {
  2404. api.setEnabled(editor.selection.isEditable());
  2405. onChanged(api);
  2406. };
  2407. editor.on('NodeChange', nodeChanged);
  2408. nodeChanged();
  2409. return () => {
  2410. editor.off('NodeChange', nodeChanged);
  2411. };
  2412. };
  2413. const isCodeSampleSelection = editor => {
  2414. const node = editor.selection.getStart();
  2415. return editor.dom.is(node, 'pre[class*="language-"]');
  2416. };
  2417. const register = editor => {
  2418. const onAction = () => editor.execCommand('codesample');
  2419. editor.ui.registry.addToggleButton('codesample', {
  2420. icon: 'code-sample',
  2421. tooltip: 'Insert/edit code sample',
  2422. onAction,
  2423. onSetup: onSetupEditable(editor, api => {
  2424. api.setActive(isCodeSampleSelection(editor));
  2425. })
  2426. });
  2427. editor.ui.registry.addMenuItem('codesample', {
  2428. text: 'Code sample...',
  2429. icon: 'code-sample',
  2430. onAction,
  2431. onSetup: onSetupEditable(editor)
  2432. });
  2433. };
  2434. var Plugin = () => {
  2435. global$2.add('codesample', editor => {
  2436. register$2(editor);
  2437. setup(editor);
  2438. register(editor);
  2439. register$1(editor);
  2440. editor.on('dblclick', ev => {
  2441. if (isCodeSample(ev.target)) {
  2442. open(editor);
  2443. }
  2444. });
  2445. });
  2446. };
  2447. Plugin();
  2448. })();